<script>
import {
  storeManagement_DelAPI,
  storeManagement_ImportAPI,
} from "@/api/data/store-management";
import dmbTable from "@/components/LTable/index.vue";
import {
  tableBase,
  cellStyle,
  headerCellStyle,
  tableFormStyle,
  formItemStyle,
} from "./config";
import { mapState } from "vuex";
import { expressCompany_DelAPI } from "@/api/data/express-company.js";
import dayjs from "dayjs";
const defaultForm = {};

export default {
  name: "extra-long-fee",
  computed: {
    ...mapState({
      company: (state) => state.custom_dict.company,
    }),
    formItemStyle() {
      return formItemStyle;
    },
    tableFormStyle() {
      return tableFormStyle;
    },
    cellStyle() {
      return cellStyle;
    },
    headerCellStyle() {
      return headerCellStyle;
    },
    tableBase_Compute() {
      return this.tableBase;
    },
  },
  components: { dmbTable },
  data() {
    return {
      propsSearchForm: { ...defaultForm },

      requestConfig: {
        url: "/base/company/list",
        method: "get",
        montage: true,
      },
      saveRequest: {
        url: "/base/company/save",
        method: "post",
        montage: false,
        updateCache: true,
      },
      selectionArr: [], // 多选框内容

      inputfile: null,
      tableBase,
    };
  },
  methods: {
    // 删除商铺
    del(id) {
      this.$confirm("确定要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        expressCompany_DelAPI(id).then(() => {
          this.$refs.table.getListData();
          this.$message.success("删除成功");
        });
      });
    },

    // 导出
    downLoad() {
      if (this.selectionArr.length > 0) {
        const ids = this.selectionArr.map((item) => {
          return item.id;
        });
        this.download(
          "/base/company/export",
          {
            ids,
          },
          `快递公司_${dayjs().format("YYYY-MM-DD hh:mm:ss")}.xlsx`
        );
      } else {
        this.$message.error("请选择条数据导出");
      }
    },
  },
};
</script>

<template>
  <div>
    <div class="mb-3">
      <template class="flex flex-row-reverse">
        <div class="my-3 flex flex-row-reverse">
          <div>
            <el-button type="success" @click="$refs.table.getListData()"
              >查询</el-button
            >
            <el-button type="success" @click="$refs.table.saveToUpdate()"
              >保存</el-button
            >
            <el-button type="primary" @click="downLoad">导出</el-button>
          </div>
        </div>
      </template>
    </div>
    <div>
      <dmb-table
        ref="table"
        :prop-list="tableBase_Compute"
        :operateWether="true"
        :is-operate="true"
        :show-index-column="true"
        select-column-type="CHECKBOX"
        :isSaveToUpadate="true"
        :req-request="requestConfig"
        :saveRequest="saveRequest"
        select-key="id"
        :cell-style="cellStyle"
        :header-cell-style="headerCellStyle"
        :initialize="false"
        :change-search-form="false"
        :show-footer="true"
        :form-item-style="tableFormStyle"
        @selectionChange="
          (row) => {
            selectionArr = row;
          }
        "
      >
        <template v-slot:operate="{ row }">
          <el-button type="danger" v-if="row.id" @click="del(row.id)"
            >删除</el-button
          >
        </template>
        <template v-slot:tmsStatus="{ row }">
          <el-checkbox v-model="row.tmsStatus" :true-label="1" :false-label="0">
          </el-checkbox>
        </template>
      </dmb-table>
    </div>
  </div>
</template>

<style scoped lang="scss">
</style>
